package com.proxyIp;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class NoProxyIpDialog extends AlertDialog implements OnClickListener {

    private OnClickListener mNoProxyListener;
    private View mNoProxyView;
    private TextView mAddNoProxyIpText;
    private String mNoProxyIpAddress;
    private boolean edit;
    private TextView subtitle;

    protected NoProxyIpDialog(Context context, OnClickListener listener) {
        super(context);
        mNoProxyListener = listener;
        edit = false;
    }

    protected NoProxyIpDialog(Context context, OnClickListener listener,
            String address) {
        super(context);
        mNoProxyListener = listener;
        mNoProxyIpAddress = address;
        edit = true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setInverseBackgroundForced(true);
        mNoProxyView = getLayoutInflater().inflate(R.layout.no_proxy_ip_dialog,
                null);
        setView(mNoProxyView);

        setButton(BUTTON_POSITIVE, getContext().getText(R.string.confirm),
                mNoProxyListener);
        setButton(BUTTON_NEGATIVE, getContext()
                .getText(R.string.cancel), mNoProxyListener);
        if (!edit) {
            mAddNoProxyIpText = (TextView) mNoProxyView
                    .findViewById(R.id.add_no_proxy_ip);
        } else {
            mAddNoProxyIpText = (TextView) mNoProxyView
                    .findViewById(R.id.add_no_proxy_ip);
            mAddNoProxyIpText.setText(mNoProxyIpAddress);
        }
        super.onCreate(savedInstanceState);
        subtitle = (TextView) findViewById(R.id.subtitle);
        if (!edit) {
            subtitle.setText(R.string.add_address);
        } else {
            subtitle.setText(R.string.edit_address);
        }
    }

    @Override
    public void onClick(View v) {
    }

    public String getAddNoProxyIp() {
        return mAddNoProxyIpText.getText().toString();
    }

    public boolean isEdit() {
        return edit;
    }

}
